﻿/*
   Copyright 2013 Dmitry Bratus

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Flower.Client;
using Flower.Logging;
using Flower.Services;
using Flower.Services.Clients;
using Sample.DataContracts;

namespace Sample.Runner
{
    public partial class Program
    {
        private static readonly Log Log = LogManager.CreateLog("Program");

        private static FlowerClient _flowerClient;

        public static void Main(string[] args)
        {
            var settings = new FlowerClientSettings
            {
                EnableCallbacks = true
            };

            using (_flowerClient = new FlowerClient(new WcfClientFactory<IDirectory>().Create("Directory"), settings))
            {
                foreach (string arg in args)
                {
                    try
                    {
                        if (arg == "ForkBomb")
                        {
                            ForkBomb(PayloadAction.None);
                        }
                        else if (arg == "ForkBombInvoke")
                        {
                            ForkBomb(PayloadAction.Invoke);
                        }
                        else if (arg == "ForkBombExecAsync")
                        {
                            ForkBomb(PayloadAction.ExecAsync);
                        }
                        else if (arg == "MessageChain")
                        {
                            MessageChain("Tests/MessageChain");
                        }
                        else if (arg == "QueueMessageChain")
                        {
                            MessageChain("Tests/QueueMessageChain");
                        }
                        else if (arg == "Competition")
                        {
                            Competition();
                        }
                        else if (arg == "Callback")
                        {
                            Callback();
                        }
                        else if (arg == "Broken")
                        {
                            Broken();
                        }
                        else if (arg == "Echo")
                        {
                            Echo();
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(arg + " failed.", ex);
                    }
                }
            }
        }
    }
}
